package com.youyi.yyviewsdklibrary.View;

import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lkx.liandianqinew.R;

public class MyButtomView extends LinearLayout {
    private ImageView mCancel;
    private onItemClickListener mOnItemClickListener;
    private TextView mSure;
    private TextView mTitle;

    public interface onItemClickListener {
        void onCancelClick(View view);

        void onSureClick(View view);
    }

    public MyButtomView(Context context) {
        super(context);
    }

    public void setOnItemClickListener(onItemClickListener onitemclicklistener) {
        this.mOnItemClickListener = onitemclicklistener;
    }

    public MyButtomView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.MyButtomView);
        String string = obtainStyledAttributes.getString(R.styleable.MyButtomView_title);
        String string2 = obtainStyledAttributes.getString(R.styleable.MyButtomView_tvSure);
        int i = 0;
        int color = obtainStyledAttributes.getColor(R.styleable.MyButtomView_yImgColor, 0);
        int color2 = obtainStyledAttributes.getColor(R.styleable.MyButtomView_ytitleColor, 0);
        int color3 = obtainStyledAttributes.getColor(R.styleable.MyButtomView_ysureColor, 0);
        boolean z = obtainStyledAttributes.getBoolean(R.styleable.MyButtomView_showCancel, true);
        boolean z2 = obtainStyledAttributes.getBoolean(R.styleable.MyButtomView_showSure, true);
        View inflate = LayoutInflater.from(context).inflate(R.layout.view_buttom_title, (ViewGroup) this, true);
        this.mCancel = (ImageView) inflate.findViewById(R.id.tv_cancel);
        this.mTitle = (TextView) inflate.findViewById(R.id.tv_title);
        this.mSure = (TextView) inflate.findViewById(R.id.tv_sure);
        if (color != 0) {
            try {
                this.mCancel.setColorFilter(color);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (color2 != 0) {
            try {
                this.mTitle.setTextColor(color2);
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        if (color3 != 0) {
            try {
                this.mSure.setTextColor(color3);
            } catch (Exception e3) {
                e3.printStackTrace();
            }
        }
        this.mTitle.setText(TextUtils.isEmpty(string) ? "标题" : string);
        this.mSure.setText(TextUtils.isEmpty(string2) ? "确定" : string2);
        this.mCancel.setVisibility(z ? View.VISIBLE : View.GONE);
        this.mSure.setVisibility(!z2 ? 8 : i);
        this.mCancel.setOnClickListener(new OnClickListener() {
            /* class com.youyi.yyviewsdklibrary.View.MyButtomView.AnonymousClass1 */

            public void onClick(View view) {
                if (MyButtomView.this.mOnItemClickListener != null) {
                    MyButtomView.this.mOnItemClickListener.onCancelClick(view);
                }
            }
        });
        this.mSure.setOnClickListener(new OnClickListener() {
            /* class com.youyi.yyviewsdklibrary.View.MyButtomView.AnonymousClass2 */

            public void onClick(View view) {
                if (MyButtomView.this.mOnItemClickListener != null) {
                    MyButtomView.this.mOnItemClickListener.onSureClick(view);
                }
            }
        });
    }

    public void setTitle(String str) {
        TextView textView = this.mTitle;
        if (textView != null) {
            textView.setText(str);
        }
    }

    public void setTvSure(String str) {
        TextView textView = this.mSure;
        if (textView != null) {
            textView.setText(str);
        }
    }

    public void showCancel(boolean z) {
        ImageView imageView = this.mCancel;
        if (imageView != null) {
            imageView.setVisibility(z ? View.VISIBLE : View.GONE);
        }
    }

    public void showSure(boolean z) {
        TextView textView = this.mSure;
        if (textView != null) {
            textView.setVisibility(z ? View.VISIBLE : View.GONE);
        }
    }
}
